package edu.hawaii.duedates;

import java.util.List;

/**
 * DueDates is an application that submits a request to specifically defined library systems, and 
 * returns the requested information of a user's checked out books and their due dates.
 * Arguments are passed from command line (in the program's main) and rendered by a library
 * parser (LibraryParser) to retrieve the requested information given the user's credentials for 
 * a certain library system.
 * @author Anthony Du Vincent Lueng
 */
public class DueDates {
  // Library parser.
  private final LibraryManager libManager;
  // List of libraries.
  private final List<Library> libraries;

//  String to = "vincent.m.l.leung@gmail.com";
//  String host = "smtp-server.hawaii.rr.com";
//  String message = "Test email";
  /**
   * DueDates constructor for initialization.
   * @param args String array of command line arguments.
   */
  public DueDates(String[] args) {
    libManager = new LibraryManager(args);
    libraries = libManager.getLibraries();
//    new EmailUser(to, host, message);
  }
  /**
   * GetDueDates displays the due dates.
   * @throws Exception when an error occurs.
   */
  public void getDueDates() throws Exception {
    for (Library lib : libraries) {
      List<LibraryUser> libUsers = lib.getLibUsers();
      for (LibraryUser u : libUsers) {
        if (lib.getLibInfo(u) == null) {
          List<Book> books = libManager.getBooks(lib);
          System.out.println(lib.getLibName());
          if (books.isEmpty()) {
            System.out.println("*Sorry, no books dued at this time*");
          }
          for (Book b : books) {
            System.out.println(b);
          }
        }
        else {
          System.out.println(lib.getLibName() + "\n" + lib.getLibInfo(u));  
        }
        System.out.println();
      }
    }
  }
  /**
   * DueDates main method to call our logger and execute library system requests.
   * @param args containing options and options with parameters.
   * @throws Exception when an error occurs.
   */
  public static void main(String[] args) throws Exception {
    DueDates duedate = new DueDates(args);
    duedate.getDueDates();
  }
}
